package com.lucy.rabc.entity;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.lucy.common.converter.JpaColumnConverter;
import com.lucy.rabc.domain.converter.PostExtendConverter;
import com.lucy.rabc.domain.extend.PostExtend;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
import lombok.Setter;
import lombok.ToString;
import org.hibernate.Hibernate;
import org.hibernate.annotations.GenericGenerator;
import org.springframework.data.annotation.CreatedBy;
import org.springframework.data.annotation.CreatedDate;
import org.springframework.data.annotation.LastModifiedBy;
import org.springframework.data.annotation.LastModifiedDate;
import org.springframework.data.jpa.domain.support.AuditingEntityListener;
import org.springframework.http.HttpStatus;

import javax.persistence.*;
import java.io.Serializable;
import java.util.Date;
import java.util.Objects;


@Getter
@Setter
@ToString
@RequiredArgsConstructor
@Entity
@Table(name = "sys_post")
@EntityListeners(AuditingEntityListener.class)
@ApiModel(value = "岗位信息")
public class SysPost implements Serializable {

    @Id
    @GeneratedValue(strategy= GenerationType.IDENTITY)
    @ApiModelProperty(value = "岗位ID",name = "id")
    Long id;

    @ApiModelProperty(value = "岗位编码")
    @Column(name = "post_code")
    String postCode;

    @ApiModelProperty(value = "岗位名称")
            @Column(name = "post_name")
    String postName;


    @ApiModelProperty(value = "岗位排序")
    @Column(name = "post_sort")
    Integer postSort;

    @ApiModelProperty(value = "岗位状态")
    @Column(name = "post_status")
    Integer status;

    @ApiModelProperty(value = "岗位备注")
    @Column(name = "remark",length = 1024)
    String remark;

    @Convert(converter = PostExtendConverter.class)
    @ApiModelProperty(value = "岗位拓展信息")
    @Column(name = "post_extend")
    PostExtend postExtend;



    @CreatedDate
    @JsonFormat(pattern="yyyy-MM-dd HH:mm:ss",timezone = "GMT+8")
    @ApiModelProperty(value = "记录创建时间",name = "createdTime")
    @Column(name = "created_time")
    private Date createdTime;
    @LastModifiedDate
    @JsonFormat(pattern="yyyy-MM-dd HH:mm:ss",timezone = "GMT+8")
    @ApiModelProperty(value = "记录更新时间",name = "updatedTime")
    @Column(name = "updated_time")
    private Date updatedTime;

    @CreatedBy
    @ApiModelProperty(value = "记录创建者",name = "createdTime")
    @Column(name = "create_user_id")
    private Long createUserId;


    @LastModifiedBy
    @Column(name = "modify_user_id")
    @ApiModelProperty(value = "记录修改者",name = "createdTime")
    private Long modifyUserId;

    @Override
    public boolean equals(Object o) {
        if (this == o) {
            return true;
        }
        if (o == null || Hibernate.getClass(this) != Hibernate.getClass(o)) {
            return false;
        }
        SysPost nepuPost = (SysPost) o;
        return id != null && Objects.equals(id, nepuPost.id);
    }

    @Override
    public int hashCode() {
        return getClass().hashCode();
    }
}
